
const user = {
    state: {
        info: {
            id: "",
            avatar: "",
            followerCount: "",
            username: "",
            brief: "",
            concernCount: "",
            visitCount: "",
            access: "",
            refresh: "",
            is_login: false,
        }
    },
    getters: {
    },
    mutations: {
        updateFollowerCount(state, followerCount) {
            state.followerCount = followerCount;
            localStorage.setItem("userinfo",JSON.stringify(state.info))
        },
        updateConcernCount(state, concernCount) {
            state.concernCount = concernCount;
            localStorage.setItem("userinfo",JSON.stringify(state.info))
        },
        addConcernCount(state) {
            state.concernCount = state.concernCount + 1;
            localStorage.setItem("userinfo",JSON.stringify(state.info))
        },
        reduceConcernCount(state) {
            state.concernCount = state.concernCount - 1;
            localStorage.setItem("userinfo",JSON.stringify(state.info))
        },
        updateUser(state, user) {
            state.info.id = user.id
            state.info.avatar = user.photo
            state.info.username = user.username
            state.info.followerCount = user.followerCount
            state.info.brief = user.brief
            state.info.concernCount = user.concernCount
            state.info.visitCount = user.visitCount
            state.info.is_login = true
            localStorage.setItem("userinfo",JSON.stringify(state.info))
        },

        clear(state) {
            state.info.id = ""
            state.info.avatar = ""
            state.info.username = ""
            state.info.followerCount = 0
            state.info.brief = ""
            state.info.concernCount = ""
            state.info.visitCount = 0
            state.info.is_login = false
        },

        updateToken(state, token) {
            state.info.access = token.access
            state.info.refresh = token.refresh
        },

        updateAccess(state, access) {
            state.info.access = access
        },
        updateUserInfoByLoc(state,userinfo){
            state.info.id = userinfo.id;
            state.info.avatar = userinfo.avatar;
            state.info.followerCount = userinfo.followerCount;
            state.info.username = userinfo.username;
            state.info.brief = userinfo.brief;
            state.info.concernCount = userinfo.concernCount;
            state.info.visitCount = userinfo.visitCount;
            state.info.is_login = true;
        }
    },
    actions: {
    },
    modules: {
    }
}

export default user;
